package cn.elead.chaos.framework.web.serializer;

import java.io.IOException;
import java.time.LocalDateTime;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import cn.elead.chaos.core.util.DateUtil;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;

/**
 * 将LocalDate转成String返回到前台
 * 
 * @author luopeng
 *
 */
public class LocalDateTimeJsonSerializer extends JsonSerializer<LocalDateTime> {

	@Override
	public void serialize(LocalDateTime date, JsonGenerator gen, SerializerProvider serializers) throws IOException {
		if(ObjectUtil.isEmpty(date)) {
			gen.writeString(StrUtil.EMPTY);
			return;
		}
		gen.writeString(DateUtil.formatLocalDateTimeToString(date));
	}

}
